<?php
namespace app\tadmin\controller\category;
use app\tadmin\controller\Controller as BaseController;
use app\common\model\Tag as TagModel;
use think\facade\Request;
/**
 * 文档-标签管理
 * Class Index
 * @package app\tadmin\controller
 */
class Tag extends BaseController{

    public function index(){
        $tag_name = input('get.tag_name' , '');
        if(!empty($tag_name)){
            $list = TagModel::where('tag_name' , $tag_name)->order('tag_type asc')->paginate(15);    
        }else{
            $list = TagModel::order('tag_type asc')->paginate(15);
        }
        //print_r(ArticleDocModel::getLastSql());
        return $this->fetch('index' , compact('list'));
    }


    public function change(){
        if ($this->request->isAjax()) {
            $id = input('post.id');
            $tag_type = input('post.tag_type');
            $tag = TagModel::get($id);
            $tag->tag_type = $tag_type;
            if($tag->save()){
                return $this->renderSuccess('success');
            }
        }
        return $this->renderError('error'); 
    }

    public function changes(){
        if ($this->request->isAjax()) {
            $ids = input('post.ids');
            $tag_type = input('post.tag_type');
            foreach($ids as $id){
                $tag = TagModel::get($id);
                $tag->tag_type = $tag_type; 
                $tag->save();
            }
            return $this->renderSuccess('success');
        }
        return $this->renderError('error'); 
    }

}